package com.example.administrator.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.administrator.myapplication.uilts.PeiZhiActivity;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by 董豪华 on 2017/1/6.
 */
public class MonthAcitivity extends AppCompatActivity {
    private TextView nameyue;
    private TextView dateyue;
    private TextView allyueyue;
    private TextView healthyue;
    private TextView loveyue;
    private TextView moneyyue;
    private TextView workyue;
    String xingzuo;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.monthxingzuo);
        Intent intent = getIntent();
        xingzuo = intent.getStringExtra("xingzuo");
        inin();
        shujufanhui(xingzuo);
    }
    public void shujufanhui(String consName){
        String url = "http://web.juhe.cn:8080/constellation/getAll?consName="+consName+"&type=month&key=4ab3d0b2232c72d9c3dc4747baf8cf4f";
        StringRequest request = new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                jiexiyue(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        PeiZhiActivity.mrequestQueue.add(request);
    }
    private void inin() {
        nameyue = (TextView) findViewById(R.id.nameyue);
        dateyue = (TextView) findViewById(R.id.dateyue);
        allyueyue = (TextView) findViewById(R.id.allyueyue);
        healthyue = (TextView) findViewById(R.id.healthyue);
        loveyue = (TextView) findViewById(R.id.loveyue);
        moneyyue = (TextView) findViewById(R.id.moneyyue);
        workyue = (TextView) findViewById(R.id.workyue);
    }
    /*月*/
    public void jiexiyue(String response){
        try {
            JSONObject jsonObject3 = new JSONObject(response);
            String date = jsonObject3.optString("date");
            String name = jsonObject3.optString("name");
            String all = jsonObject3.optString("all");
            String happyMagic = jsonObject3.optString("happyMagic");
            String health = jsonObject3.optString("health");
            String love = jsonObject3.optString("love");
            String money = jsonObject3.optString("money");
            String month = jsonObject3.optString("month");
            String work = jsonObject3.optString("work");
            String resultcode = jsonObject3.optString("resultcode");
            String error_code = jsonObject3.optString("error_code");
            nameyue.setText(name);
            dateyue.setText(date);
            allyueyue.setText("综合:\n"+all);
            healthyue.setText("健康:\n"+health);
            loveyue.setText("爱情:\n"+love);
            moneyyue.setText("财运:\n"+money);
            workyue.setText("工作:\n"+work);
        } catch (JSONException e) {
            e.printStackTrace();
            Toast.makeText(MonthAcitivity.this,"解析异常",Toast.LENGTH_LONG).show();
        }
    }
}
